package a_exception.b_throw;
/*
    throw抛出异常
 */
public class ThrowDemo {
    //获取元素
    public static Object getElement(int index,int[] arr){
        if (index < 0 || index > arr.length - 1){
            //抛出指定异常(创建异常)
            throw new RuntimeException("index下标越界了!!!!");
            //return null;
        }
        int element = arr[index];
        return element;
    }

    //throws
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5};
        //try - catch
        Object element = ThrowDemo.getElement(7, arr);
        System.out.println(element);
    }
}
